//
//  JCBaseNavSearchView.m
//  MedicalPlatform
//
//  Created by zhangtao on 2018/7/23.
//  Copyright © 2018年 liuerpan. All rights reserved.
//

#import "JCBaseNavSearchView.h"

@implementation JCBaseNavSearchView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
    
        _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _searchBar.searchBarStyle = UISearchBarStyleMinimal;
        _searchBar.placeholder = @"搜索内容";

//        UITextField * searchField = [_searchBar valueForKey:@"_searchField"];
//        [searchField setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
//        [searchField setValue:[UIFont boldSystemFontOfSize:12] forKeyPath:@"_placeholderLabel.font"];
//        _searchBar.backgroundImage = [UIImage imageNamed:@"whitebg.png"];
//
        [self addSubview:_searchBar];
        
    }
    return self;
}



-(void)setSearchBackImg:(NSString *)searchBackImg{
    _searchBar.backgroundImage = [UIImage imageNamed:searchBackImg];

}

-(void)setPlaceholder:(NSString *)placeholder{
    _searchBar.placeholder =placeholder;
}

-(void)setFieldBgColor:(UIColor *)fieldBgColor{
     UITextField * searchField = [_searchBar valueForKey:@"searchField"];
    
    searchField.backgroundColor = fieldBgColor;
}

-(void)setBoardColor:(UIColor *)boardColor{
     UITextField * searchField = [_searchBar valueForKey:@"searchBarTextField"];
    searchField.backgroundColor = [UIColor whiteColor];
    self.searchBar.layer.borderColor = lightGreen.CGColor;
    self.searchBar.layer.cornerRadius = self.searchBar.frame.size.height/2;
    self.searchBar.layer.masksToBounds = YES;
    self.searchBar.layer.borderWidth = 1;
//    for (UIView *view in self.searchBar.subviews) {
//
//        if ([view isKindOfClass:NSClassFromString(@"_UISearchBarSearchFieldBackgroundView")]) {
//            UIImageView *v = (UIImageView *)view;
//            v.image = [UIImage imageNamed:@"whitebg.png"];
//        }
//
//        if([view isKindOfClass:NSClassFromString(@"UISearchBarTextField")]) {
//            UITextField *textField = (UITextField *)view;
//            //添加右按钮
//            [self addVoiceButton:textField];
//            //设置输入框的背景颜色
//            textField.clipsToBounds = YES;
//            textField.backgroundColor = [UIColor whiteColor];
            //设置输入框边框的圆角以及颜色
//            textField.layer.cornerRadius = self.searchBar.frame.size.height/2.0f;
//            textField.layer.borderColor = deepGreen.CGColor;
//            textField.layer.borderWidth = 1;
            //设置输入字体颜色
//            textField.textColor = [UIColor P2Color];
//            //设置默认文字颜色
//            textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@" 搜索" attributes:@{NSForegroundColorAttributeName:[UIColor P2Color]}];
//        }
//    }

    
    
    
    
    
//    for (UIView *view in self.searchBar.subviews) {
//        if ([view isKindOfClass:NSClassFromString(@"UIView")]&&view.subviews.count>0) {
//            view.backgroundColor = boardColor;
//            [[view.subviews objectAtIndex:0] removeFromSuperview];
//            break;
//        }
//    }
}

-(void)setSearchBarIcon:(NSString *)searchBarIcon{
    [self.searchBar setImage:[UIImage imageNamed:searchBarIcon]
            forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
